package com.sclg.utils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;

import org.apache.commons.dbcp2.BasicDataSource;



public class jdbcUtils {
	public static Connection getConnection() {
		BasicDataSource bs = new BasicDataSource();
		Connection con = null;
		try {
			Properties prop = new Properties();
			prop.load(jdbcUtils.class.getClassLoader().getResourceAsStream("db.properties"));
			String driver = prop.getProperty("driver");
			String url = prop.getProperty("url");
			String username = prop.getProperty("username");
			String pwd = prop.getProperty("pwd");
			bs.setDriverClassName(driver);
			bs.setUrl(url);
			bs.setUsername(username);//3213123123123
			bs.setPassword(pwd);
			con = bs.getConnection();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return con;
	}
	public static void closeConnection(ResultSet set,Connection con,PreparedStatement pstmt) {
		try {
			if (set != null) {
				set.close();
			}
			if (con != null) {
				con.close();
			}
			if (pstmt != null) {
				pstmt.close();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
